package com.wenshi.app.fragment;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wenshi.app.delegate.WsWiewDelegate;
import com.wenshi.view.IKeyValue;
import com.wenshi.view.WsViewTools;


import java.util.HashMap;


/**
 * 该类是所有组件Fragment的父类
 */
public abstract class WsBaseFragment extends Fragment implements WsWiewDelegate.IReLoadContent {

    private Context mContent;
    private View root;
    /**
     * 代理类
     */
    WsWiewDelegate wsWiewDelegate;

    protected abstract void onViewReady();

    public LayoutInflater inflater;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContent = this.getActivity();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.inflater = inflater;
        root = inflater.inflate(WsViewTools.getResource(mContent, "wsview_activity_ws_base", "layout"), container,false);
        return  root;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        wsWiewDelegate = new WsWiewDelegate(mContent,root);
        wsWiewDelegate.setHeaderVisible(false);
        onViewReady();
    }

    /**
     *该方法返回一个代理类
     *
     */
    public WsWiewDelegate getWsWiewDelegate()
    {
        return  wsWiewDelegate;
    }


    /**
     *
     *用于绑定视图和数据的方法
     *
     */
    public void renderView(IKeyValue data)
    {
        WsViewTools.renderView(mContent,root,data);
    }
    /**
     *用来返回LayoutInflater
     */
    public LayoutInflater getInflater(){
        return  inflater;
    }

    /**
     * 查找id的方法 用于控件fragment
     *
     *
     *
     */
    public View findViewById(int id )
    {
       return root.findViewById(id);
    }
}
